#!/usr/local/bin/python
# -*- coding: utf-8 -*-

from data_alchemy.app_config_alchemy import AppConfigAlchemy
from initLogger import logger
import json

#功能：用于管理复杂的配置信息

def readConfig(configName):
    '''
    函数功能：读取指定的配置项信息
    :param configName:  配置项名称“PROPERTY_NAME_JSON”或“OWNERSHIP_NAME_JSON”
    :return:
    '''
    appConfigAlchemy = AppConfigAlchemy()
    appConfigInfor = appConfigAlchemy.GetConfigItem(configName)
    logger.debug("config_value:%s"% (appConfigInfor.config_value))
    return appConfigInfor.config_value

def writeConfig(configName, configValue):
    '''
    函数功能：读取指定的配置项信息
    :return:
    '''
    appConfigAlchemy = AppConfigAlchemy(configName=configName,
                                        configValue =configValue,
                                        remark="")
    appConfigAlchemy.AddConfigItem()


def addNewExpandTypeName(tradeTypeDic):
    '''
    函数功能：将新的支付类型添加到配置文件数据库中
    :param expandTypeList:
    :return:
    '''

    ownershipStr = readConfig("OWNERSHIP_NAME_JSON")
    ownershipInfoJson = json.loads(ownershipStr)

    logger.debug(ownershipInfoJson)
    expandDic = ownershipInfoJson["权属"]["自有"]["本年结余"]["日常"]["支出"]
    #newExpandNameList = tradeTypeDic.keys()

    for expandName in tradeTypeDic:
        expandDic[expandName] =""

    ownershipInfoJson["权属"]["自有"]["本年结余"]["日常"]["支出"]= expandDic

    newOwnershipStr = json.dumps(ownershipInfoJson)

    writeConfig("OWNERSHIP_NAME_JSON", newOwnershipStr)

def getInvestmentProductList():
    '''
    函数功能：获取投资产品列表信息
    :return:
    '''

    propertyStr = readConfig("PROPERTY_NAME_JSON")
    propertyInfoJson = json.loads(propertyStr)

    logger.debug(propertyInfoJson)
    investmentProductDic = propertyInfoJson["资产"]["投资"]["理财"]
    investmentProductList = list(investmentProductDic.keys())

    logger.debug("investmentProductList: %s"%(str(investmentProductList)))


    return investmentProductList




"""
class ConfigManage():
    '''
    类功能：用于管理复杂的配置信息
    '''

    def readConfig(configName):
        '''
        函数功能：读取指定的配置项信息
        :return:
        '''
        appConfigAlchemy = AppConfigAlchemy()
        appConfigInfor = appConfigAlchemy.GetConfigItem(configName)
        return appConfigInfor.config_value

"""

def main():
    investmentList = getInvestmentProductList()
    logger.debug(investmentList)

if __name__ == "__main__":
    main()